'''
Author: 精金电子 maicent@qq.com
Date: 2025-02-07 21:41:50
LastEditors: 精金电子 maicent@qq.com
LastEditTime: 2025-02-07 22:18:18
FilePath: \fastapi\main.py
Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
'''
from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles
from fastapi.openapi.docs import get_swagger_ui_html
import uvicorn
from apps.app01.urls import router as items_router
from apps.app02.urls import router as users_router
from apps.post.urls import router as post_router
from apps.formData.urls import router as formData_router
from apps.fileUpload.urls import router as fileUpload_router


app = FastAPI(
    title="FastAPI学习项目",
    description="这是一个用于学习FastAPI的示例项目",
    version="1.0.0",
    docs_url=None,  # 禁用默认的swagger文档
    redoc_url="/redoc"
)

# 挂载静态文件目录
app.mount("/static", StaticFiles(directory="static"), name="static")

app.include_router(items_router,prefix="/app01",tags=["app01 路径参数"])
app.include_router(users_router,prefix="/app02",tags=["app02 查询参数"])
app.include_router(post_router,prefix="/post",tags=["post 请求体"])
app.include_router(formData_router,prefix="/formData",tags=["formData 表单数据"])
app.include_router(fileUpload_router,prefix="/fileUpload",tags=["fileUpload 文件上传"])

@app.get("/",
    tags=["根路径"],

    summary="根路径访问",
    description="这是网站的根路径，返回一个简单的欢迎消息",
    response_description="返回包含欢迎消息的JSON对象"
)
def read_root():
    """
    返回欢迎消息
    
    这个端点返回一个简单的欢迎消息作为JSON对象
    
    Returns:
        dict: 包含欢迎消息的字典
    """
    return {"message": "Hello World"}

@app.get("/docs", include_in_schema=False)
async def custom_swagger_ui_html():
    return get_swagger_ui_html(
        openapi_url=app.openapi_url,
        title=app.title + " - Swagger UI",
        oauth2_redirect_url=app.swagger_ui_oauth2_redirect_url,
        swagger_js_url="/static/swagger-ui-bundle.js",
        swagger_css_url="/static/swagger-ui.css",
    )

if __name__ == "__main__":
    uvicorn.run(
        "main:app", 
        host="127.0.0.1", 
        port=8000, 
        reload=True,
        log_level="debug"
    )
